package com.xt.xxb.taobao;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.Map;

/**
 * 获取拼多多省市区
 *
 * @author xt
 * @date 2019年7月27日11:39:49
 */
public class TbResponse<T> {
    private boolean success;
    /**
     * 错误码
     */
    private String errorCode;
    /**
     * 错误消息
     */
    private String errorMsg;
    private T data;

    private TbResponse() {
    }

    private TbResponse(boolean success, String errorCode, String errorMsg, T data) {
        this.success = success;
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
        this.data = data;
    }

    public static TbResponse success(String data) {
        return new TbResponse<>(true, null, null, data);
    }

    public static TbResponse success(Map<String, String> data) {
        return new TbResponse<>(true, null, null, data);
    }

    public static TbResponse success() {
        return new TbResponse<>(true, null, null, null);
    }

    public static TbResponse success(JSONArray data) {
        return new TbResponse<>(true, null, null, data);
    }

    public static TbResponse success(JSONObject data) {
        return new TbResponse<>(true, null, null, data);
    }

    public static TbResponse fail(String errorCode, String errorMsg) {
        return new TbResponse<>(false, errorCode, errorMsg, null);
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "TbResponse{" +
                "success=" + success +
                ", errorCode='" + errorCode + '\'' +
                ", errorMsg='" + errorMsg + '\'' +
                ", data=" + data +
                '}';
    }
}
